#ifndef __TM1638_H__
#define __TM1638_H__
//#include "stm32f10x.h"
//#include "sys.h"
//#include "delay.h"
#include "my_include.h"

extern u8 DispTab[4];
extern u8 KeyValue[4];  //保存按键值
extern u8 Update_disp_flg;
#define TM1638_STB                 PCout(7)
#define TM1638_CLK                 PCout(8)
#define TM1638_DIO_IN              {GPIOC->CRH&=0XFFFFFF0F;GPIOC->CRH|=(u32)8<<4;}
#define TM1638_DIO_OUT             {GPIOC->CRH&=0XFFFFFF0F;GPIOC->CRH|=(u32)3<<4;}             
#define TM1638_DIO_DataOUT         PCout(9)
#define TM1638_DIO_DataIN          PCin(9)



//地址命令设置
#define TM1638_GRID1  0xc0
#define TM1638_GRID2  0xc1
#define TM1638_GRID3  0xc2
#define TM1638_GRID4  0xc3
#define TM1638_GRID5  0xc4
#define TM1638_GRID6  0xc5
#define TM1638_GRID7  0xc6
#define TM1638_GRID8  0xc7

#define TM1638_GRID9  0xc8
#define TM1638_GRID10 0xc9
#define TM1638_GRID11 0xca
#define TM1638_GRID12 0xcb
#define TM1638_GRID13 0xcc
#define TM1638_GRID14 0xcd
#define TM1638_GRID15 0xce
#define TM1638_GRID16 0xcf


//数据命令设置
/*
#define 0x40   //写数据到显示寄存器
#define 0x42   //读键扫数据
#define 0x40   //自动地址增加
#define 0x44   //固定地址
#define 0x40   //普通模式
#define 0x48   //测试模式
*/

//显示
/*
#define 0x80   //显示关
#define 0x88   //显示开
*/

/*****************新版动环修改led灯*******************************/
#define SysBlueLed(s)        Digital_led(8,1,s)   //系统运行灯
#define NetRedLed(s)         Digital_led(8,2,s)   //网络状态灯
#define PwrONULed(s)         Digital_led(8,3,s)   //光猫电源灯
#define PwrPBXLed(s)         Digital_led(8,4,s)   //交换机电源灯
#define PmokeLed(s)          Digital_led(8,5,s)   //烟雾状态灯

#define WaterLed(s)          Digital_led(8,6,s)   //水浸状态灯
#define InfraredLed(s)       Digital_led(8,7,s)   //红外状态灯
#define Door_Sensor1LED(s)   Digital_led(8,8,s)   //门磁1状态灯
#define Door_Sensor2LED(s)   Digital_led(9,1,s)   //门磁2状态灯
#define Door_ControlLED(s)   Digital_led(9,2,s)   //门禁状态灯


/******************老物联双色LED灯**************************/
#define SysBlueLed(s)        Digital_led(8,1,s)
#define NetRedLed(s)         Digital_led(8,2,s)
#define PwrBlueLed(s)        Digital_led(8,3,s)
#define PwrRedLed(s)         Digital_led(8,4,s)
#define RS485BlueLed(s)      Digital_led(8,5,s)
#define GSMRedLed(s)         Digital_led(8,6,s)
#define NetLinkBlueLed(s)    Digital_led(8,7,s)
#define reserved1(s)         Digital_led(8,8,s)

#define ExchangerBlueLed(s)  Digital_led(9,1,s)
#define reserved2(s)         Digital_led(9,2,s)
#define Camera1BlueLed(s)    Digital_led(10,1,s)
#define reserved3(s)         Digital_led(10,2,s)

#define Camera2BlueLed(s)    Digital_led(10,3,s)
#define reserved4(s)         Digital_led(10,4,s)
#define Camera3BlueLed(s)    Digital_led(10,5,s)
#define reserved5(s)         Digital_led(10,6,s)
#define Camera4BlueLed(s)    Digital_led(10,7,s)
#define reserved6(s)         Digital_led(10,8,s)
#define reserved7(s)         Digital_led(11,1,s)
#define reserved8(s)         Digital_led(11,2,s)



#define LED1_BLUE(s)        Digital_led(8,1,s)//LED1蓝灯
#define LED1_RED(s)         Digital_led(8,2,s)//LED1红灯


#define LED2_BLUE(s)        Digital_led(8,3,s)//LED2蓝灯
#define LED2_RED(s)         Digital_led(8,4,s)//LED2红灯


#define LED3_BLUE(s)        Digital_led(8,5,s)//LED3蓝灯
#define LED3_RED(s)         Digital_led(8,6,s)//LED3红灯


#define LED4_BLUE(s)        Digital_led(8,7,s)//LED4蓝灯
#define LED4_RED(s)         Digital_led(8,8,s)//LED4红灯

#define LED5_BLUE(s)        Digital_led(9,1,s)//LED5蓝灯
#define LED5_RED(s)         Digital_led(9,2,s)//LED5红灯


#define LED6_BLUE(s)        Digital_led(10,1,s)//LED6蓝灯
#define LED6_RED(s)         Digital_led(10,2,s)//LED6红灯


#define LED7_BLUE(s)        Digital_led(10,3,s)//LED7蓝灯
#define LED7_RED(s)         Digital_led(10,4,s)//LED7红灯


#define LED8_BLUE(s)            Digital_led(10,5,s)//LED8蓝灯
#define LED8_RED(s)         Digital_led(10,6,s)//LED8红灯


#define LED9_BLUE(s)            Digital_led(10,7,s)//LED9蓝灯
#define LED9_RED(s)         Digital_led(10,8,s)//LED9红灯


#define LED10_BLUE(s)       Digital_led(11,1,s)//LED10蓝灯
#define LED10_RED(s)        Digital_led(11,2,s)//LED10红灯


void Read_key(u8 *KeyValue);
void TM1638_Init(void);
void dispclear(u8 n,u8 m);
void Flicker(uint8_t n);
void display_led(u8 dig,u8 dat);
void display(u8 dig,u8 dat);
void DigitalTube_led(u8 dig,u8 Data,u8 onoff);
void UpdateDisp(void);
void Write_DATA(u8 add,u8 DATA);
#endif

